<template>
<view>
<view class="main_box">
  <view class="ticket_top_bg">
    <image mode="aspectFill" class="ticket_top_bg_img" :src="productData.productInfo.imagePath"></image>
  </view>
  <view class="ticket_info">
    <view class="ticket_base_info">
      <view class="ticket_base_info_left">
        <image mode="aspectFill" class="ticket_img" :src="productData.productInfo.imagePath"></image>
      </view>
      <view class="ticket_base_info_right">
        <text class="ticket_name">{{productData.productInfo.name}}</text>
        <view class="ticket_price_block">
          <text class="price" :style="'color:' + color" v-if="productData.productInfo.promotion>0">￥{{productData.productInfo.promotionPrice}}</text>
          <text class="price" :style="'color:' + color" v-else>￥{{productData.productInfo.price}}</text>
          <text class="price" :style="'color:' + color" v-if="productData.productInfo.maxPrice>productData.productInfo.price">-{{productData.productInfo.maxPrice}}</text>
          <text v-if="productData.productInfo.unitShow" class="unitShow">/{{productData.productInfo.unitShow}}</text>
          <text v-if="productData.productInfo.maxPrice<=productData.productInfo.price&&productData.productInfo.tagPrice>productData.productInfo.price" class="tag_price">￥{{productData.productInfo.tagPrice}}</text>
        </view>
      </view>
      <!--折扣  -->
      <view class="discount" v-if="productData.productInfo.discount" :style="'background:' + color + ';box-shadow:2rpx 2rpx 14rpx ' + color">
        <text style="font-size:32rpx;font-weight: bold;">{{productData.productInfo.discount}}</text>
        <text style="font-size:24rpx;">折起</text>
      </view>
    </view>
    <view class="ticket_detail_info">
      <view class="ticket_detail_info_one">
        <view class="ticket_sale_time">
          <image class="ticket_item_icon" src="https://image1.sansancloud.com/xianhua/2019_6/13/16/17/59_428.jpg?x-oss-process=style/preview_120"></image>
          <text class="ticket_sale_time_text">{{productData.productInfo.readyTimeStr}}</text>
        </view>
        <view class="ticket_perform_addr">
          <view class="ticket_perform_addr_left">
            <image class="ticket_item_icon" src="https://image1.sansancloud.com/xianhua/2019_6/13/16/19/10_399.jpg?x-oss-process=style/preview_120"></image>
            <text class="ticket_perform_addr_text">{{productData.productInfo.location}}</text>
          </view>
          <view class="navTo" @tap="clickCatch">
            <image class="navTo_icon" src="https://image1.sansancloud.com/xianhua/2019_6/13/16/21/37_88.jpg?x-oss-process=style/preview_120"></image>
          </view>
        </view>
      </view>
      <!-- 核销列表 -->
      <view class="verification_block" v-if="scanExhauseList.length!=0">
        <view class="verification_title">
          <view class="verification_title_item" style="width:30%">
            <text>项目名称</text>
          </view>
          <view class="verification_title_item" style="width:50%">
            <text>项目内容</text>
          </view>
          <view class="verification_title_item" style="width:20%">
            <text>项目次数</text>
          </view>
        </view>
        <view class="verification_list">
          <view class="verification_item" v-for="(item, index) in scanExhauseList" :key="index">
            <text class="verification_item_data" style="width:30%">{{item.name}}</text>
            <text class="verification_item_data" style="width:50%">{{item.remark}}</text>
            <text class="verification_item_data" style="width:20%">{{item.count}}次</text>
          </view>
        </view>
      </view>
      <!-- 首页组件-私有产品详情装饰-->
      <custom-page-index-component :receiveData="sendProductData" v-if="sendProductData"></custom-page-index-component> 
      <view class="ticket_description" v-if="productData.description.description!=''&&productData.description.description!='<p><br></p>'">
        <text class="ticket_description_title">详情介绍</text>
        <!-- 富文本 -->
        <view class="ticket_description_text">
          <view class="wxParseHtmlContainer">
              <!-- <rich-text :nodes="articleJsonData.jsonData.content" v-if="articleJsonData"></rich-text> -->
              <rich-text-component :receiveData="articleJsonData" v-if="articleJsonData"></rich-text-component>
              <!-- <component is="init" :wxParseData="article.nodes"></component> -->
          </view>
        </view>
      </view>
      <!-- 首页组件-公共产品详情装饰-->
      <custom-page-index-component :receiveData="sendIndexData" v-if="sendIndexData"></custom-page-index-component>
    </view>
  </view>
</view>
<!-- 底部按钮 -->
<view class="ticket_bottom_block">
  <view class="ticket_bottom_block_left">
    <button open-type="contact" plain="true" hover-class="none" style="border:none" class="ticket_kefu">
      <image class="ticket_kefu_icon" src="https://image1.sansancloud.com/xianhua/2019_6/13/17/9/7_869.jpg?x-oss-process=style/preview_120"></image>
    </button>
    <view class="ticket_favorite" :data-itemId="productData.productInfo.productId" @click.stop="productData.productInfo.favorite==0?'addToFavourite':'removeFavourite'">
      <image v-if="productData.productInfo.favorite==1" class="ticket_favorite_icon" src="https://image1.sansancloud.com/xianhua/2019_6/13/17/56/48_461.jpg?x-oss-process=style/preview_120"></image>
      <image v-if="productData.productInfo.favorite==0" class="ticket_favorite_icon" src="https://image1.sansancloud.com/xianhua/2019_6/13/17/9/7_881.jpg?x-oss-process=style/preview_120"></image>
    </view>
  </view>
  <view class="ticket_bottom_block_right">
    <view class="ticket_buy" data-way="buy" @tap="readyPay2" :style="'background:' + color">
      <text class="ticket_buy_text">立即购票</text>
    </view>
  </view>
</view>
<measure-card-component v-if='showCount' :showCount="showCount" :pintuanParams="pintuanParams" :productData='productData' :byNowParams="byNowParams" :bindway="bindway" @closeCard="getCloseCardFun"></measure-card-component>
 <!-- <component is="measure_card2" :setting="minCount" :focusData="productData.productInfo" :measures="productData.measures" :byNowParams="byNowParams" :measurementJson="measurementJson" :type="bindway"></component> -->
</view>
</template>

<script>

// import posters from "../../view/partials/canvas/index";
// import time from "../../view/partials/time/time";
// import pintuan from "../../view/partials/pintuan_popup/index";
// import componentCustompage from "../../view/partials/custom_page/index";

export default {
  data() {
    return {
      setting: null,
      // setting 
      productData: null,
      // 商品数据 
      cart: null,
      countGood: 0,
      sysWidth: 320,
      //图片大小
      showCount: false,
      saleStrategyState: false,
      measuresState: false,
      positionState: false,
      attrsState: false,
      targs: [],
      posterState: false,
      pintuanPopupState: false,
      proId: '',
      shopId: '',
      bindway: 'cart',
      //点击的是加入购物车或者立即购买
      showState: 0,
      commitList: [],
      measurementJson: null,
      qrCodeUrl: "",
      haveMeasuresState: false,
      selectTypeData: null,
      swiperIndex: 1,
      totalImg: 0,
      pintuanId: 0,
      pintuanState: false,
      promotionState: false,
      pintuanListData: [],
      color: '',
      secondColor: "",
      clientNo: '',
      minCount: '1',
      sendIndexData: {},
      buyType: 'normal',
      scanExhauseList: [],
      dataFOr_getData: {
        id: '',
        addShopId: ''
      },
      byNowParams: {
        productId: '',
        itemCount: 1,
        shopId: '',
        cartesianId: '0',
        fromSource: 'mini',
        orderType: ''
      },
      pintuanParams: {
        pintuanCreateType: 0,
        pintuanRecordId: 0
      },
      showGuigeType: false,
      pintuanParam: "",
      visiblePintuanNum: 0,
      sendProductData: "",
      loginUser: "",
      article_article: "",
      articleJsonData:null,
    };
  },
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('--------product----------', options);
    let that = this;
    that.setData({
      proId: options.id || options.productId,
      shopId: options.addShopId || 236,
      clientNo: getApp().globalData.clientNo,
      color: getApp().globalData.setting.platformSetting.defaultColor,
      secondColor: getApp().globalData.setting.platformSetting.secondColor
    });
    let sendIndexData = JSON.stringify({
      title: 'noTitle',
      url: "productdetail",
      params: {
        pageObjectId: options.id || options.productId
      }
    });
    that.setData({
      sendIndexData: sendIndexData
    });
    let sendProductData = JSON.stringify({
      title: 'noTitle',
      url: "product_detail_" + (options.id || options.productId)
    });
    that.setData({
      sendProductData: sendProductData
    });
    console.log("商品id和店铺id", options);
    that.dataFOr_getData.id = options.id || options.productId;
    that.dataFOr_getData.addShopId = options.addShopId || 236;
    that.setData({
      dataFOr_getData: that.dataFOr_getData
    });
    that.getData(options);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    let that = this;
    that.setData({
      setting: getApp().globalData.setting,
      loginUser: getApp().globalData.loginUser
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log('===onReachBottom====');
  },
  methods: {
    /* 删除收藏 */
    removeFavourite: function (e) {
      var that = this; // wx.showLoading({
      //   title: 'loading'
      // })

      getApp().globalData.showToastLoading('loading', true);
      var postData = {
        itemId: '',
        favoriteType: '1'
      };
      let productData = this.productData;
      postData.itemId = e.currentTarget.dataset.itemid;
      var customIndex = getApp().globalData.AddClientUrl("/remove_favorite.html", postData, 'post');
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log(res.data);

          if (res.data.errcode == '0') {
            productData.productInfo.favorite = 0;
            that.setData({
              productData: productData
            });
            wx.showToast({
              title: '已取消收藏！',
              image: '/wxcomponents/images/icons/tip.png',
              duration: 1000
            });
            console.log('000---' + that.productData.productInfo.favorite);
          }
        },
        fail: function (res) {
          getApp().globalData.loadFail();
        },
        complete: function (res) {
          wx.hideLoading();
        }
      });
    },

    /* 加入收藏 */
    addToFavourite: function (e) {
      var that = this;
      var postData = {
        itemId: '',
        favoriteType: '1'
      }; // wx.showLoading({
      //   title: 'loading'
      // })

      getApp().globalData.showToastLoading('loading', true);
      let productData = this.productData;
      postData.itemId = e.currentTarget.dataset.itemid;
      console.log(postData);
      var customIndex = getApp().globalData.AddClientUrl("/add_to_favorite.html", postData, 'post');
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log(res.data);

          if (res.data.errcode == '0') {
            productData.productInfo.favorite = 1;
            that.setData({
              productData: productData
            });
            wx.showToast({
              title: '已收藏！',
              icon: 'success',
              duration: 1000
            });
            console.log('111---' + that.productData.productInfo.favorite);
          }
        },
        fail: function (res) {
          getApp().globalData.loadFail();
        },
        complete: function (res) {
          wx.hideLoading();
        }
      });
    },
    // 定位
    clickCatch: function (e) {
      console.log(this.productData.productInfo);
      let latitude = this.productData.productInfo.latitude;
      let longitude = this.productData.productInfo.longitude;
      let name = this.productData.productInfo.name;
      let address = this.productData.productInfo.location;
      wx.openLocation({
        latitude: latitude,
        longitude: longitude,
        scale: 12,
        name: name,
        address: address
      });
    },
    getData: function (options) {
      let param = {};
      let that = this;

      if (!options) {
        param = that.dataFOr_getData;
      } else {
        param = options;
      } // wx.showLoading({
      //   title: 'loading'
      // })


      getApp().globalData.showToastLoading('loading', true);
      console.log('==param===', param);
      let postParam = {};
      postParam.productId = param.id || param.productId;
      postParam.addShopId = param.addShopId || 236;
      let customIndex = getApp().globalData.AddClientUrl("/product_detail.html", postParam);
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log(res);

          if (res.data.productInfo.errcode == -1) {
            wx.showToast({
              title: res.data.productInfo.relateObj,
              image: '/wxcomponents/images/icons/tip.png',
              duration: 1000
            });
            return;
          }

          that.setData({
            pintuanState: false
          });
          console.log('--------------getData-------------');
          let scanExhauseList = '';

          if (res.data.productInfo.scanExhauseList) {
            scanExhauseList = JSON.parse(res.data.productInfo.scanExhauseList);
            that.setData({
              scanExhauseList: scanExhauseList.items
            });
          }

          res.data.productInfo.promotion = Number(res.data.productInfo.promotion);

          if (res.data.productInfo && res.data.productInfo.promotionBean) {
            that.setData({
              promotionState: true
            });

            if (res.data.productInfo.promotionBean.promotionStatus == 2) {
              that.setData({
                color: '#888',
                secondColor: '#fff'
              });
            }
          }

          if (res.data.images) {
            that.setData({
              totalImg: res.data.images.length
            });
          }

          if (res.data.productInfo && res.data.productInfo.tags) {
            let tagsStr = res.data.productInfo.tags;
            let tagsStr2 = tagsStr.replace(/\[/g, '');
            let tagArr = tagsStr2.split(']');
            tagArr.length--;
            that.setData({
              targs: tagArr
            });
            console.log('targs', that.targs);
          }

          if (res.data.productInfo.tagPrice > res.data.productInfo.price) {
            let discount = (Number(res.data.productInfo.price) / Number(res.data.productInfo.tagPrice) * 10).toFixed(1);
            res.data.productInfo.discount = discount;
          }

          that.setData({
            productData: res.data
          });
          if (res.data.description && res.data.description.description) {
          			let articleJsonData=res.data.description.description;
          			that.setData({
          			  articleJsonData: {jsonData:{content:articleJsonData}}
          			});
            console.log('====articleJsonData====', that.articleJsonData);
          }
          // if (res.data.description && res.data.description.description) {
          //   //WxParse.wxParse('article', 'html', res.data.description.description, that, 10)
          //   setTimeout(function () {
          //     that.article_article = res.data.description.description;
          //   });
          //   console.log('====article====', that.article);
          // }

          if (res.data.productInfo.saleStrategy && res.data.productInfo.saleStrategy != 0) {
            that.setData({
              saleStrategyState: true
            });
            console.log('====saleStrategyState====', that.saleStrategyState);
          }

          if (res.data.measuresState && res.data.measuresState.length != 0) {
            that.setData({
              measuresState: true
            });
            console.log('====measuresState====', that.measuresState);
          }

          if (res.data.productInfo.latitude && res.data.productInfo.latitude != 0) {
            that.setData({
              positionState: true
            });
            console.log('====positionState====', that.positionState);
          }

          if (res.data.attrs && res.data.attrs.length != 0) {
            that.setData({
              attrsState: true
            });
            console.log('====attrsState====', that.attrsState);
          }

          if (!!res.data.productInfo) {
            let info = res.data.productInfo;
            let postPatam = {}; //var paramStr = 'page=1&productId=' + info.productId+'&shopId=' + info.belongShopId

            postPatam.page = 1;
            postPatam.productId = info.productId;
            postPatam.shopId = info.belongShopId;
          }

          console.log('productData', that.productData);
        },
        fail: function (res) {
          console.log("====fail=====");
          getApp().globalData.loadFail();
        },
        complete: function (res) {
          wx.hideLoading();
        }
      });
    },
    readyPay2: function (e) {
      console.log('====e=====', e);

      // if (!getApp().globalData.checkIfLogin()) {
      //   return;
      // }
      if(!getApp().globalData.loginUser){
          let url="productDetail.html?id="+this.proId;
          let backUrl=encodeURIComponent(url)
          getApp().globalData.checkIfLogin(backUrl);
          return
      }
      if (this.productData.productInfo.promotionBean && this.productData.productInfo.promotionBean.promotionStatus == 2) {
        console.log('活动已结束！');
        wx.showToast({
          title: '活动已结束！',
          image: '/wxcomponents/images/icons/tip.png',
          duration: 1000
        });
        return;
      }

      let productData = this.productData;
      let way;
      let pintuanRecordId;
      console.log(productData);

      if (e.currentTarget.dataset.way) {
        way = e.currentTarget.dataset.way;
        pintuanRecordId = e.currentTarget.dataset.pintuanid;
      } else {
        way = e.detail.data.way;
        pintuanRecordId = e.detail.data.pintuanid;
      }

      this.setData({
        bindway: way
      });
      console.log('====q=====', this.bindway);
      let info = productData.productInfo;
      this.byNowParams.productId = info.productId;
      this.byNowParams.shopId = info.belongShopId;
      this.setData({
        byNowParams: this.byNowParams
      });

      if (way == 'cart') {
        if (productData.measures.length == 0) {
          this.addtocart();
        } else {
          this.setData({
            showCount: true
          });
          this.byNowParams.orderType = 0;
          this.setData({
            byNowParams: this.byNowParams
          });
          this.chooseMeasureItem();
        }
      } else if (way == 'pintuanOne') {
        //单独购买
        this.setData({
          showCount: true
        });
        this.byNowParams.orderType = 0;
        this.pintuanParams.pintuanCreateType = 0;
        this.pintuanParams.pintuanRecordId = 0;
        this.setData({
          byNowParams: this.byNowParams,
          pintuanParams: this.pintuanParams
        });
        this.chooseMeasureItem();
      } else if (way == 'pintuanMore') {
        //参加拼团
        this.setData({
          showCount: true
        });
        this.byNowParams.orderType = 0;
        this.pintuanParams.pintuanCreateType = 1;
        this.pintuanParams.pintuanRecordId = 0;
        this.setData({
          byNowParams: this.byNowParams,
          pintuanParams: this.pintuanParams
        });
        this.chooseMeasureItem();
      } else if (way == 'addPintuan') {
        //发起拼单
        this.setData({
          showCount: true
        });
        this.setData({
          pintuanPopupState: false
        });
        this.byNowParams.orderType = 0;
        this.pintuanParams.pintuanCreateType = 2;
        this.pintuanParams.pintuanRecordId = pintuanRecordId;
        this.setData({
          byNowParams: this.byNowParams,
          pintuanParams: this.pintuanParams
        });
        this.chooseMeasureItem();
      } else if (way == 'select') {
        this.setData({
          showCount: true
        });
        this.byNowParams.orderType = 0;
        this.setData({
          byNowParams: this.byNowParams
        });
        this.chooseMeasureItem();
      } else {
        this.setData({
          showCount: true
        });
        this.byNowParams.orderType = 0;
        this.setData({
          byNowParams: this.byNowParams
        });
        this.chooseMeasureItem();
      }
    },
    closeZhezhao: function () {
      this.setData({
        showCount: false
      });
    },
    subNum: function () {
      if (this.measurementJson.id) {
        this.setData({
          minCount: this.measurementJson.minSaleCount
        });
      } else {
        this.setData({
          minCount: 1
        });
      }

      if (this.byNowParams.itemCount == this.minCount) {
        return;
      }

      this.byNowParams.itemCount--;
      this.setData({
        byNowParams: this.byNowParams
      });
    },
    addNum: function () {
      this.byNowParams.itemCount++;
      this.setData({
        byNowParams: this.byNowParams
      });
    },

    /* 立即购买 */
    buyNow: function (e) {
      if (!getApp().globalData.checkShopOpenTime()) {
        return;
      }

      if (!getApp().globalData.checkIfLogin()) {
        return;
      }

      let bindway;

      if (e.currentTarget.dataset.way) {
        bindway = e.currentTarget.dataset.way;
      } else {
        bindway = this.bindway;
      }

      console.log('=======bindway======', bindway);

      if (bindway == 'cart') {
        this.setData({
          haveMeasuresState: true
        });
        this.setData({
          selectTypeData: this.selectTypeData
        });
        console.log('-----------addtocart----------');
        this.addtocart();
      } else if (bindway == 'pintuanOne') {
        this.setData({
          haveMeasuresState: true
        });
        this.setData({
          selectTypeData: this.selectTypeData
        });
        console.log('-----------addtocart----------');
        this.createOrder22(this.byNowParams);
      } else if (bindway == 'pintuanMore') {
        this.setData({
          haveMeasuresState: true
        });
        this.setData({
          selectTypeData: this.selectTypeData
        });
        console.log('-----------addtocart----------');
        this.createOrder22(this.byNowParams);
      } else if (bindway == 'addPintuan') {
        this.setData({
          haveMeasuresState: true
        });
        this.setData({
          selectTypeData: this.selectTypeData
        });
        console.log('-----------addtocart----------');
        this.createOrder22(this.byNowParams);
      } else {
        console.log('-----------buyNow----------');
        this.createOrder22(this.byNowParams);
      }
    },

    /* 创建订单 */
    createOrder22: function (o) {
      console.log('========createOrder22======', o);
      let that = this;
      let productInfo = that.productData.productInfo;
      let params = Object.assign({}, params, that.byNowParams, that.pintuanParams);

      if (productInfo.preOrderCustomFormId) {
        let url;

        if (that.byNowParams.cartesianId) {
          url = '/pages/form_detail/index?customFormId=' + productInfo.preOrderCustomFormId + '&productId=' + productInfo.productId + '&params=' + JSON.stringify(params);
        } else {
          url = '/pages/form_detail/index?customFormId=' + productInfo.preOrderCustomFormId + '&productId=' + productInfo.productId;
        }

        wx.navigateTo({
          url: url
        });
        return;
      } else {
        // wx.showLoading({
        //   title: 'loading',
        //   mask: true
        // })
        getApp().globalData.showToastLoading('loading', true);
        getApp().globalData.createOrder(that.byNowParams, that.pintuanParams);
      }
    },
    postParams: function (data) {
      var that = this;
      var customIndex = getApp().globalData.AddClientUrl("/change_shopping_car_item.html", data, 'post');
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log('---------------change_shopping_car_item-----------------');
          console.log(res.data);
          wx.hideLoading();

          if (that.bindway == 'cart') {
            that.setData({
              showCount: false
            });
          }

          if (data.productId == 0) {
            console.log('购物车里面的商品数量');
            that.setData({
              countGood: res.data.totalCarItemCount
            });
          } else {
            if (res.data.productId && res.data.productId != 0) {
              if (data.count == 0) {
                console.log('通过加入购物车来确定购物车里面的商品数量');
              } else {
                wx.showToast({
                  title: '加入购物车成功'
                });
              }

              if (!!res.data.totalCarItemCount || res.data.totalCarItemCount == 0) {
                that.setData({
                  countGood: res.data.totalCarItemCount
                });
              }
            } else {
              wx.showToast({
                title: res.data.errMsg,
                image: '/wxcomponents/images/icons/tip.png',
                duration: 2000
              });
            }
          }

          try {
            getApp().globalData.carChangeNotify(res.data);
          } catch (e) {}
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },
    //提交规格产品
    submitMeasure: function (id) {
      var that = this;
      let focusProduct = this.MeasureItem;
      let measurementJson = this.measurementJson;
      let data = {};
      data.cartesianId = measurementJson.id;
      data.productId = focusProduct.id;
      data.shopId = focusProduct.belongShopId;
      data.count = 1;
      data.type = 'add';
      var customIndex = getApp().globalData.AddClientUrl("/change_shopping_car_item.html", data, 'post');
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log('--------add----------');
          console.log(res.data);
          that.setData({
            showGuigeType: false
          });
        },
        fail: function (res) {
          getApp().globalData.loadFail();
        },
        complete: function () {
          wx.hideLoading();
        }
      });
    },
    //获取规格价格参数
    get_measure_cartesionFun: function () {
      console.log('get_measure_cartesion');
      this.setData({
        measurementJson: {
          waitDataState: false
        }
      });
      let productId = this.productData.productInfo.productId;
      let postStr = '';

      if (this.MeasureParams.length == 0) {
        this.byNowParams.cartesianId = '0';
        this.setData({
          measurementJson: {
            waitDataState: true
          }
        }); //没有规格时 不需要等待请求

        return;
      }

      for (let i = 0; i < this.MeasureParams.length; i++) {
        postStr += this.MeasureParams[i].value + ',';
      }

      let param = {};
      param.productId = productId;
      param.measureIds = postStr;
      console.log(postStr);
      let customIndex = getApp().globalData.AddClientUrl("/get_measure_cartesion.html", param);
      var that = this;
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log(res.data);
          that.byNowParams.cartesianId = res.data.id;
          that.setData({
            measurementJson: res.data
          });
          that.measurementJson.waitDataState = true;
          that.setData({
            measurementJson: that.measurementJson
          });
          that.byNowParams.itemCount = that.measurementJson.minSaleCount;
          that.setData({
            byNowParams: that.byNowParams
          });
          that.setData({
            minCount: that.byNowParams.itemCount
          });
        },
        fail: function (res) {
          console.log("fail");
          getApp().globalData.loadFail();
        },
        complete: function () {}
      });
    },

    /* 初始化 选规格 */
    chooseMeasureItem: function (event) {
      console.log('----------初始化规格参数-----------', event);
      let productData = this.productData;
      let focusProduct = productData;
      let selectTypeData = [];

      for (let i = 0; i < focusProduct.measures.length; i++) {
        focusProduct.measures[i].checkedMeasureItem = 0; //初始化选择的数据

        let param = {};
        let selectTypeDataItem = {};
        param.name = focusProduct.measures[i].name;
        param.value = focusProduct.measures[i].productAssignMeasure[0].id;
        selectTypeDataItem.type = focusProduct.measures[i].name;
        selectTypeDataItem.value = focusProduct.measures[i].productAssignMeasure[0].measureName;
        console.log('=====param=====', param);
        this.MeasureParams.push(param);
        selectTypeData.push(selectTypeDataItem);
      }

      this.selectTypeData = selectTypeData;
      console.log('====that.data.selectTypeData======', this.selectTypeData);
      this.setData({
        productData: focusProduct
      });
      console.log('===MeasureParams====', this.MeasureParams);
      this.get_measure_cartesionFun();
    },
    //选择规格小巷的---显示
    radioChange: function (e) {
      let that = this;
      let flag = false;
      console.log("====radioChange=====", e);
      console.log('====that.data.selectTypeData======', that.selectTypeData);

      if (that.selectTypeData) {
        console.log('1111111');

        for (let i = 0; i < that.selectTypeData.length; i++) {
          if (e.currentTarget.dataset.type == that.selectTypeData[i].type) {
            that.selectTypeData.splice(i, 1, e.currentTarget.dataset);
            flag = true;
          }
        }

        if (!flag) {
          that.selectTypeData.splice(that.selectTypeData.length, 1, e.currentTarget.dataset);
          flag = false;
        }
      } else {
        console.log('222222');
        that.selectTypeData = [];
        that.selectTypeData.splice(0, 1, e.currentTarget.dataset);
        that.setData({
          selectTypeData: that.selectTypeData
        });
      }

      console.log('====that.data.selectTypeData======', that.selectTypeData);
      let index = e.currentTarget.dataset.index;
      let indexJson = getApp().globalData.getSpaceStr(index, '-'); //console.log(indexJson)

      let focusItem = that.productData;
      focusItem.measures[indexJson.str1].checkedMeasureItem = indexJson.str2;
      that.setData({
        productData: focusItem
      });
    },
    //选择规格小巷---获取数据
    chooseMeasure: function (e) {
      console.log(e.detail.value);
      let chooseMeasureJson = getApp().globalData.getSpaceStr(e.detail.value, '-');
      console.log(chooseMeasureJson);

      for (let i = 0; i < this.MeasureParams.length; i++) {
        if (this.MeasureParams[i].name == chooseMeasureJson.str1) {
          this.MeasureParams[i].value = chooseMeasureJson.str2;
        }
      }

      this.get_measure_cartesionFun();
    },
    closeGuigeZhezhao: function () {
      this.setData({
        showGuigeType: false
      });
      this.MeasureParams = [];
    },

    /**
     * 生命周期函数--监听页面加载
     */
    getPintuanData: function (productId, promotionId) {
      let that = this;
      let data = {
        status: 1,
        productId: productId,
        promotionId: promotionId
      };
      that.setData({
        pintuanParam: data
      });
      var pintuanUrl = getApp().globalData.AddClientUrl("/wx_find_pintuan_records.html", data, 'post');
      wx.request({
        url: pintuanUrl.url,
        data: pintuanUrl.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log('--------add----------');
          console.log(res.data);
          that.setData({
            pintuanListData: res.data.relateObj.result
          });

          if (that.pintuanListData.length == 1) {
            that.setData({
              visiblePintuanNum: 1
            });
          } else {
            that.setData({
              visiblePintuanNum: 2
            });
          }
        },
        fail: function (res) {
          getApp().globalData.loadFail();
        },
        complete: function () {
          wx.hideLoading();
        }
      });
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
@import "./index.css";
</style>